package com.single.service;

import java.text.DecimalFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Calendar;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.config.dao.EquStateConfigDao;
import com.config.dao.EquipmentDao;
import com.config.dao.LineConfigDao;
import com.config.dao.ShiftConfigDao;
import com.config.entity.EquStateConfig;
import com.config.entity.Equipment;
import com.config.entity.ShiftConfig;
import com.data.dao.BaseDataDao;
import com.data.dao.ChargeDayDao;
import com.data.dao.ChargeMinDao;
import com.data.dao.ChargeMonthDao;
import com.data.dao.ChargeWeekDao;
import com.data.dao.StateDayDao;
import com.data.dao.StateMinDao;
import com.data.dao.StateMonthDao;
import com.data.dao.StateShiftDao;
import com.data.dao.StateWeekDao;
import com.data.entity.BaseData;
import com.data.entity.ChargeDay;
import com.data.entity.ChargeMin;
import com.data.entity.ChargeMonth;
import com.data.entity.ChargeWeek;
import com.data.entity.StateDay;
import com.data.entity.StateMin;
import com.data.entity.StateMonth;
import com.data.entity.StateShift;
import com.data.entity.StateWeek;
import com.single.dao.SingleDao;

@Service("singleService")
public class SingleServiceImpl implements SingleService{
	@Resource(name="baseDataDao")
	private  BaseDataDao baseDataDao;
	@Resource(name="lineConfigDao")
	private LineConfigDao lineConfigDao;
	@Resource(name="equipmentDao")
	private  EquipmentDao equipmentDao;
	@Resource(name="shiftConfigDao")
	private ShiftConfigDao shiftConfigDao;
	@Resource(name="equStateConfigDao")
	private  EquStateConfigDao equStateConfigDao;
	@Resource(name="singleDao")
	private  SingleDao singleDao;
	@Resource(name="stateMinDao")
	private  StateMinDao stateMinDao;
	@Resource(name="stateDayDao")
	private StateDayDao stateDayDao;
	@Resource(name="stateWeekDao")
	private StateWeekDao stateWeekDao;
	@Resource(name="stateMonthDao")
	private StateMonthDao monthDao;
	@Resource(name="chargeMinDao")
	private ChargeMinDao chargeMinDao;
	@Resource(name="chargeDayDao")
	private ChargeDayDao chargeDayDao;
	@Resource(name="chargeWeekDao")
	private ChargeWeekDao chargeWeekDao;
	@Resource(name="chargeMonthDao")
	private ChargeMonthDao chargeMonthDao;
	@Resource(name="stateShiftDao")
	private StateShiftDao stateShiftDao;
	
	/**
	 * 查询单机设备日分析数据
	 * @param lineId
	 * @param equId
	 * @param belongDate
	 */
	@Override
	public void getSingleDayData(int lineId, int equId, String belongDate,Map<String, Object> model) {
		DecimalFormat  df=new DecimalFormat ("0.0");
		List<String> pieLendge=new ArrayList<String>();
		List<Map<String,Object>> pieValue=new ArrayList<Map<String,Object>>();
		SimpleDateFormat formatter = new SimpleDateFormat("HH:mm");
		List<String> xTimes=Arrays.asList(new String[]{"00:30", "01:00", "01:30", "02:00", "02:30", "03:00", "03:30", "04:00", "04:30", "05:00", "05:30", "06:00", "06:30", "07:00", "07:30", "08:00", "08:30", "09:00", "09:30", "10:00", "10:30", "11:00", "11:30", "12:00", "12:30", "13:00", "13:30", "14:00", "14:30", "15:00", "15:30", "16:00", "16:30", "17:00", "17:30", "18:00", "18:30", "19:00", "19:30", "20:00", "20:30", "21:00", "21:30", "22:00", "22:30", "23:00", "23:30", "24:00"});//getXAxis();
		List<Double> yValue=new ArrayList<Double>();
		List<String> xTimes_p=Arrays.asList(new String[]{"00:00", "01:00", "02:00",  "03:00",  "04:00",  "05:00",  "06:00", "07:00",  "08:00", "09:00",  "10:00",  "11:00",  "12:00",  "13:00",  "14:00",  "15:00",  "16:00",  "17:00", "18:00", "19:00", "20:00",  "21:00",  "22:00",  "23:00"});//getXAxis();
		List<Double> yValue_p=new ArrayList<Double>();
		double fullLoad=0.0;double overLoad=0.0;double rate=0.0;
		Equipment equ=equipmentDao.get(equId);
	    String equName=equ.getEquName();
	    String equNo=equ.getEquNo();
	    String photoPath=equ.getEquPhoto();
		String path="";
		if(photoPath!=null){
			path="/wz_ems/up/"+photoPath;
		}else{
			path="/wz_ems/resources/img/p1.png";
		}
	    double ratedPower=equ.getRatedPower();
	    ShiftConfig  config=shiftConfigDao.findShiftsByLine(lineId, belongDate);//班制
		if(config!=null){
			//有班制
			List<ShiftConfig> shifts=shiftConfigDao.findByShiftsId(config.getId());
			if(shifts.size()>0){
				//超载报警（柱状图）
				List<StateMin> minList=stateMinDao.getStateMinsByDay(equId, "超载", belongDate);
				int i = 0;
				for(String xt:xTimes){
					Double temp = 0d;
					if(i<minList.size()){
						StateMin cm = minList.get(i);
						if(formatter.format(cm.getBelongTime()).equals("00:00")){
							i++;
						}else{
							while(formatter.format(cm.getBelongTime()).equals(xt)){
								temp = Double.parseDouble(df.format(cm.getDuration()/60));
								i++;
								break;
							}
						}
					}
					if(temp!=0d){
						yValue.add(temp);
					}else{
						yValue.add(0.0);
					}
				}
				//班次报警时长(饼状图),貌似也可以直接从stateShif表里得，而不用从min里累加
				for(ShiftConfig shift:shifts){
					pieLendge.add(shift.getShiftName());
					StateShift stateShift=stateShiftDao.getStateShiftBytypeAndDate(equId, shift.getShiftName(), "超载", belongDate);
					Map<String,Object> map=new HashMap<String,Object>();
					if(stateShift!=null){
						double t=stateShift.getDuration();
						map.put("name", shift.getShiftName());
						map.put("value", Double.parseDouble(df.format(t/60)));
						pieValue.add(map);
					}else{
						map.put("name", shift.getShiftName());
						map.put("value", 0.0);
						pieValue.add(map);
					}
				}
				StateDay overLoadByday=stateDayDao.getStateDay(equId, "超载", belongDate);
				StateDay fullLoadByday=stateDayDao.getStateDay(equId, "满载", belongDate);
				if(overLoadByday!=null&&fullLoadByday!=null){
					overLoad=Double.parseDouble(df.format(overLoadByday.getDuration()/60));
					fullLoad=Double.parseDouble(df.format(fullLoadByday.getDuration()/60));
				}
				if(fullLoad!=0.0){
					 rate=Double.parseDouble(df.format(overLoad/fullLoad*100));
				}
				//获取设备功率数据
				List<BaseData> baseList=baseDataDao.getRealTimePowers(equNo,belongDate);
				int p = 0;
				for(String xt:xTimes_p){
					Double tempCharge = 0d;
					if(p<baseList.size()){
						BaseData cm = baseList.get(p);
						while(formatter.format(cm.getTime()).equals(xt)){
							tempCharge = cm.getP_active();
							p++;
							break;
						}
					}
					if(tempCharge!=0d){
						yValue_p.add(tempCharge);
					}else{
						yValue_p.add(0.0);
					}
				}
				model.put("success", true);
			}else{
				model.put("success", false);
				model.put("msg", "该生产线无班次信息，请在基础模块配置");
			}
		}else{
			model.put("success", false);
			model.put("msg", "该生产线无班制信息，请在基础模块配置");
		}
		
		model.put("powerHour", xTimes_p);
		model.put("power", yValue_p);
		model.put("xTimes", xTimes);//超载报警横轴
		model.put("yValue", yValue);//超载报警纵轴
		model.put("pieValue", pieValue);//饼图报警时长
		model.put("pieLendge", pieLendge);//
		model.put("rate", rate);//报警占满载比重
		model.put("belongDate", belongDate);//统计时间
		model.put("overLoad", overLoad+"分钟");//超载时长
		model.put("fullLoad", fullLoad+"分钟");//满载载时长
		model.put("equName", equName);
		model.put("equNo", equNo);
		model.put("ratedPower", ratedPower+"KW");
		model.put("path", path);
	}
	
	/**
	 * 查询单机设备日综合数据
	 */
	@Override
	public void getSinglePowerCompexData(int lineId,int equId,String startTime,String endTime,Map<String, Object> model) {
		SimpleDateFormat sdft = new SimpleDateFormat("yyyy-MM-dd");
		DecimalFormat  df=new DecimalFormat ("0.0");
		List<String> days=new ArrayList<String>();//日期
		List<Double> over=new ArrayList<Double>();//每天报警时长
		List<Map<String,Object>> totalShiftOverLoad=new ArrayList<Map<String,Object>>();//第三张表的数据；[{name=早班, value=1467.0}, {name=中班, value=860.0}, {name=晚班, value=0.0}]
		List<String> shiftNames=new ArrayList<String>();//所有班次名称；[早班, 中班, 晚班]
		List<Map<String,Object>> eachShiftOverList=new ArrayList<Map<String,Object>>();//[{name=早班, value=[0.0, 547.0, 621.0, 299.0]}, {name=中班, value=[215.0, 261.0, 384.0, 0.0]}, {name=晚班, value=[0.0, 0.0, 0.0, 0.0]}]
		double totalWorkTime=0.0;//总工作时长
		String stateType="超载";
		Equipment equ=equipmentDao.get(equId);
	    String equName=equ.getEquName();
	    String equNo=equ.getEquNo();
	    String photoPath=equ.getEquPhoto();
		String path="";
		if(photoPath!=null){
			path="/wz_ems/up/"+photoPath;
		}else{
			path="/wz_ems/resources/img/p1.png";
		}
	    double ratedPower=equ.getRatedPower();	
	    double overLoadsTotal=0.0;//超载总时长
		//1.判断时间区间内是是否跨班制
		try {
			ShiftConfig e=shiftConfigDao.findShiftsByTime(lineId, startTime, endTime);
			if(e!=null){
				totalWorkTime=stateDayDao.getTotalWorkTime(equId, startTime, endTime,"");
				//2.获取日期和每日报警时长（第一张表数据）
				Long t1=sdft.parse(startTime).getTime();
				Long t2=sdft.parse(endTime).getTime();
				for(long i=t1;i<=t2;i+=86400000){
					String sd = sdft.format(new Date(i)); 
					StateDay entity=stateDayDao.getStateDay(equId, stateType, sd);
					if(entity!=null){
						over.add(Double.parseDouble(df.format(entity.getDuration()/60)));
					}else{
						over.add(0.0);
					}
					days.add(sd);
				}
				overLoadsTotal=testAdd(over);
				//3.每天班次统计报警时长
				List<ShiftConfig> shifts=shiftConfigDao.findByShiftsId(e.getId());
				if(shifts!=null){
					for(ShiftConfig shift:shifts){
						Map<String, Object> eachmap=new HashMap<String, Object>();
						List<Double> eachList=new ArrayList<Double>();
						for(String date:days){
							double shiftOverLoad=0.0;
							String strT=shiftConfigDao.gettime(shift, date);
							String[] a=strT.split("\\|");
							String time1=a[0];
							String time2=a[1];
							//班次报警时长
							shiftOverLoad=singleDao.getDurationByDate(equId, "超载", time1, time2);
							eachList.add(Double.parseDouble(df.format(shiftOverLoad/60)));
						}
						shiftNames.add(shift.getShiftName());
						eachmap.put("name",shift.getShiftName());
						eachmap.put("value", eachList);
						eachShiftOverList.add(eachmap);
					}
					totalShiftOverLoad=testAddMap(eachShiftOverList);
				}
				model.put("success", true);//判断是否跨班制
			}else{
				model.put("success", false);
				model.put("msg", "该生产线无班制或出现跨班制情况，请在基础模块配置或重新选择时间区间");
			}
			model.put("equName", equName);
			model.put("equNo", equNo);
			model.put("ratedPower", ratedPower+"KW");
			model.put("startTime", startTime);
			model.put("endTime", endTime);
			model.put("shiftNames", shiftNames);//班次
			model.put("days", days);//日期
			model.put("dayOvers", over);//每天总的报警报警时长
			model.put("eachShiftOverList", eachShiftOverList);//每天分班次的报警时长
			model.put("totalShiftOverLoad", totalShiftOverLoad);//各班次的总报警时长
			model.put("overLoadsTotal", Double.parseDouble(df.format(overLoadsTotal/60))+"小时");//总报警时长
			model.put("totalWorkTime", Double.parseDouble(df.format(totalWorkTime/60/60))+"小时");
			model.put("path", path);
		} catch (NumberFormatException e) {
			e.printStackTrace();
		} catch (ParseException e) {
			e.printStackTrace();
		}
	}

	/**
	 * 单机设备功率周分析
	 */
	@Override
	public void getSinglePowerWeekData(int equId, String stateType,int belongYear, int startWeek, int endWeek,Map<String, Object> model) {
		DecimalFormat  df=new DecimalFormat ("0.0");
		List<Integer> weeks=new ArrayList<Integer>();//周
		List<Double> overs=new ArrayList<Double>();//报警时长
		List<Double> relativeOvers=new ArrayList<Double>();//相对报警时长
		String equName="";
		String equNo="";
		double ratedPower=0.0;
		double weekOver=0.0;//超载总时长
		double totalDuration=0.0;//工作总时长
		Equipment equ=equipmentDao.get(equId);
		equName=equ.getEquName();
		equNo=equ.getEquNo();
		String photoPath=equ.getEquPhoto();
		String path="";
		if(photoPath!=null){
			path="/wz_ems/up/"+photoPath;
		}else{
			path="/wz_ems/resources/img/p1.png";
		}
		ratedPower=equ.getRatedPower();
		totalDuration=stateWeekDao.getdurationByStateAndDate(equId, belongYear,  startWeek,  endWeek,"").getDuration();
		for(int i=startWeek;i<=endWeek;i++){
			if(totalDuration!=0){
				StateWeek stateweek=stateWeekDao.getStateWeekByStateAndDate(equId, belongYear, i, stateType);
				if(stateweek!=null){
					overs.add(Double.parseDouble(df.format(stateweek.getDuration()/60)));
					weekOver+=stateweek.getDuration();
					relativeOvers.add(Double.parseDouble(df.format(stateweek.getDuration()/totalDuration*100)));
				}else{
					overs.add(0.0);
					relativeOvers.add(0.0);
				}
			}else{
				overs.add(0.0);
				relativeOvers.add(0.0);
			}
			weeks.add(i);
		}
		model.put("equName", equName);
		model.put("equNo", equNo);
		model.put("ratedPower", ratedPower+"KW");
		model.put("startTime", belongYear+"年"+startWeek+"周");
		model.put("endTime", belongYear+"年"+endWeek+"周");
		model.put("weeks", weeks);
		model.put("overs",overs);
		model.put("weekOver", Double.parseDouble(df.format(weekOver/60/60))+"小时");//超载总时长
		model.put("totalDuration", Double.parseDouble(df.format(totalDuration/60/60))+"小时");//总工作时长
		model.put("relativeOvers", relativeOvers);
		model.put("path", path);
	} 
	
	public double testAdd(List<Double> list){
		DecimalFormat  df=new DecimalFormat ("0.0");
		double total=0.0;
		for(int i=0;i<list.size();i++){
			total+=list.get(i);
		}
		return Double.parseDouble(df.format(total));
	}
	
	public List<Map<String,Object>> testAddMap(List<Map<String,Object>> list){
		List<Map<String,Object>> totalList=new ArrayList<Map<String,Object>>();
		for(int i=0;i<list.size();i++){
			double total=0.0;
			Map<String, Object> map=new HashMap<String, Object>();
			List<Double> valueList=(List<Double>) list.get(i).get("value");
			for(int j=0;j<valueList.size();j++){
				total=testAdd(valueList);
			}
			map.put("name",list.get(i).get("name"));
			map.put("value", total);
			totalList.add(map);
		}
		return totalList;
	}

	/**
	 * 单机功率月分析
	 * @param equId
	 * @param stateType：满载/空载/超载/停机/..等
	 * @param year：2016
	 * @param startMonth:7
	 * @param endMonth:8
	 * @param model
	 */
	@Override
	public void getSinglePowerMonthData(int equId, String stateType, int year,
			int startMonth, int endMonth, Map<String, Object> model) {
		DecimalFormat  df=new DecimalFormat ("0.0");
		String belongDate="";
		List<Double> list=new ArrayList<Double>();//获取每月的报警时长
		List<Double> listByRate=new ArrayList<Double>();//获取报警占总工作时长的比率
		List<String> months=new ArrayList<String>();//lenge数据
		String equName="";
		String equNo="";
		double ratedPower=0.0;
		double totalWorktime=0.0;
		String startTime="";
		String endTime="";
		if(startMonth<10){
			startTime=year+"-"+"0"+startMonth;
		}else{
			startTime=year+"-"+startMonth;
		}
		if(endMonth<10){
			endTime=year+"-"+"0"+endMonth;
		}else{
			endTime=year+"-"+endMonth;
		}
		//获取设备信息
		Equipment equ=equipmentDao.get(equId);
		equName=equ.getEquName();
		equNo=equ.getEquNo();
		String photoPath=equ.getEquPhoto();
		String path="";
		if(photoPath!=null){
			path="/wz_ems/up/"+photoPath;
		}else{
			path="/wz_ems/resources/img/p1.png";
		}
		ratedPower=equ.getRatedPower();
		//获取总工作时长
		totalWorktime=monthDao.getTotalWorkTime(equId, startTime, endTime,"");
		for(int i=startMonth;i<=endMonth;i++){
			String st="";
			if (i<10){
				st = "0"+i;
		    }
		    belongDate=year+"-"+st;
		    if(totalWorktime!=0){
		    	StateMonth entity= monthDao.getStateMonthByDate(equId, stateType, belongDate);
		    	if(entity!=null){
		    		list.add(Double.parseDouble(df.format(entity.getDuration()/60/60)));
		    		listByRate.add(Double.parseDouble(df.format(entity.getDuration()/totalWorktime*100)));
		    	}else{
		    		list.add(0.0);
		    		listByRate.add(0.0);
		    	}
		    }else{
		    	list.add(0.0);
	    		listByRate.add(0.0);
		    }
		    months.add(belongDate);
		}
		model.put("equName", equName);
		model.put("equNo", equNo);
		model.put("ratedPower", ratedPower+"KW");
		model.put("startTime", startTime);
		model.put("endTime", endTime);
		model.put("totalWorkTime", Double.parseDouble(df.format(totalWorktime/60/60))+"小时");//工作总时长
		model.put("totalOverTime",  Double.parseDouble(df.format(testAdd(list)))+"小时");//报警总时长
		model.put("listByEachMonth", list);//每月报警时长
		model.put("listByEachMonthRate", listByRate);//每月报警占总工作时长比重
		model.put("listByEachMonthLendge", months);//
		model.put("path", path);
	}

	/**
	 * 单机功率月分析之月同比
	 * @param equId
	 * @param stateType:满载/空载/超载/停机...等
	 * @param month:8
	 * @param model
	 */
	@Override
	public void getSinglePowerMonthDataBySameMonth(int equId,String stateType, int month,Map<String, Object> model) {
		DecimalFormat  df=new DecimalFormat ("0.0");
		String  belongMonth="";
		if(month<10){
			belongMonth="0"+month;
		}else{
			belongMonth=String.valueOf(month);
		}
		List<Double> listBySameMonth=new ArrayList<Double>();//相同月份的报警记录
		List<String> listBySameMonthLendge=new ArrayList<String>();//相同月份报警记录的lendge记录
		//获取第一张表的数据
		List<StateMonth> fingBySameMonthList=monthDao.getBySameMonth(equId, belongMonth, stateType);
		if(fingBySameMonthList.size()>0){
			for(StateMonth e:fingBySameMonthList){
				listBySameMonth.add(Double.parseDouble(df.format(e.getDuration()/60/60)));
				listBySameMonthLendge.add(e.getBelongDate());
			}
		}
		model.put("listBySameMonth",listBySameMonth);//月度同比报警时长(分钟)
		model.put("listBySameMonthLendge", listBySameMonthLendge);//月度同比横轴
	}

	/**
	 * 单机电度电费日分析
	 * @param lineId
	 * @param equId
	 * @param belongDate：2016-08-15
	 * @param model
	 */
	@Override
	public void getElectricityDayData(int lineId, int equId, String belongDate,
			Map<String, Object> model) {
		DecimalFormat  decf=new DecimalFormat ("0.0");
		Double total=0.0;
		double totalCharge=0.0;
		SimpleDateFormat formatter = new SimpleDateFormat("HH:mm");
		List<String> allShift=new ArrayList<String>();//柱状图的y轴
		List<String> yShifts=new ArrayList<String>();//柱状图的y轴
		List<Map<String,Object>> xValue=new ArrayList<Map<String,Object>>();//柱状图横轴
		List<String> xTimes=Arrays.asList(new String[]{"00:30", "01:00", "01:30", "02:00", "02:30", "03:00", "03:30", "04:00", "04:30", "05:00", "05:30", "06:00", "06:30", "07:00", "07:30", "08:00", "08:30", "09:00", "09:30", "10:00", "10:30", "11:00", "11:30", "12:00", "12:30", "13:00", "13:30", "14:00", "14:30", "15:00", "15:30", "16:00", "16:30", "17:00", "17:30", "18:00", "18:30", "19:00", "19:30", "20:00", "20:30", "21:00", "21:30", "22:00", "22:30", "23:00", "23:30", "24:00"});//getXAxis();
		List<Double> yValue=new ArrayList<Double>();
		List<String> pieLendge=new ArrayList<String>();
		List<Map<String,Object>> pieDValue=new ArrayList<Map<String,Object>>();
		List<Map<String,Object>> pieFValue=new ArrayList<Map<String,Object>>();
		Equipment equ=equipmentDao.get(equId);
		String equNo=equ.getEquNo();
		String equName=equ.getEquName();
		String photoPath=equ.getEquPhoto();
		String path="";
		if(photoPath!=null){
			path="/wz_ems/up/"+photoPath;
		}else{
			path="/wz_ems/resources/img/p1.png";
		}
		ShiftConfig  config=shiftConfigDao.findShiftsByLine(lineId, belongDate);//班制
		if(config!=null){
			//有班制
			List<ShiftConfig> shifts=shiftConfigDao.findByShiftsId(config.getId());
			if(shifts.size()>0){
				Map<String,Object> map;
				//满载率(横向柱状图)
				for(ShiftConfig shift:shifts){
					map=new HashMap<String,Object>();
					allShift.add(shift.getShiftName());
					yShifts.add(shift.getShiftName());
					String strT=shiftConfigDao.gettime(shift, belongDate);
					String[] a=strT.split("\\|");
					String time1=a[0];
					String time2=a[1];
					double relativeComp=chargeMinDao.getDurationByTime(equId, time1, time2).getRelativeComp();
					total+=relativeComp;
					map.put("name", shift.getShiftName());
					map.put("value", relativeComp);
					xValue.add(map);
				}
				yShifts.add("全天");
				map=new HashMap<String,Object>();
				map.put("name", "全天");
				map.put("value", total);
				xValue.add(map);
				//全天每半小时的电度情况(折线图)
				List<ChargeMin> list=chargeMinDao.getChargeMinsByDay(equId, belongDate,"N");
				int i = 0;
				for(String xt:xTimes){
					Double tempCharge = 0d;
					if(i<list.size()){
						ChargeMin cm = list.get(i);
						if(formatter.format(cm.getBelongTime()).equals("00:00")){
							i++;
						}else{
							while(formatter.format(cm.getBelongTime()).equals(xt)){
								tempCharge = cm.getRelativeComp();
								i++;
								break;
							}
						}
					}
					if(tempCharge!=0.0){
						yValue.add(tempCharge);
					}else{
						yValue.add(0.0);
					}
				}
				//获取全天电度电费信息(饼状图)
				List<ChargeDay> dayList=chargeDayDao.getChargeDayIdAndDate(equId, belongDate,"N");
				if(dayList!=null&&dayList.size()!=0){
					for(ChargeDay day:dayList){
						String chargeName=day.getChargeName();
						double charge=day.getCharge();
						Map<String,Object> fmap=new HashMap<String,Object>();
						Map<String,Object> dmap=new HashMap<String,Object>();
						pieLendge.add(chargeName+"电度");
						pieLendge.add(chargeName+"电费");
						fmap.put("name", chargeName+"电费");
						fmap.put("value", charge);
						pieFValue.add(fmap);
						dmap.put("name", chargeName+"电度");
						dmap.put("value", day.getRelativeComp());
						pieDValue.add(dmap);
						totalCharge+=charge;
					}
				}else{
					Map<String,Object> fmap=new HashMap<String,Object>();
					Map<String,Object> dmap=new HashMap<String,Object>();
					pieLendge.add("电度");
					pieLendge.add("电费");
					fmap.put("name", "电费");
					fmap.put("value", 0);
					pieFValue.add(fmap);
					dmap.put("name", "电度");
					dmap.put("value", 0);
					pieDValue.add(dmap);
				}
				model.put("success", true);
			}else{
				//该日期无效，没有班次
				model.put("success", false);
				model.put("msg", "该生产线无班次信息，请在基础模块配置");
			}
		}else{
			//该日期无效，不在班制内
			model.put("success", false);
			model.put("msg", "该生产线无班制信息，请在基础模块配置");
		}
		model.put("equNo", equNo);
		model.put("equName", equName);
		model.put("belongDate",belongDate );
		model.put("totalComp", Double.parseDouble(decf.format(total))+"度");
		model.put("totalCharge", Double.parseDouble(decf.format(totalCharge))+"元");
		model.put("xTimes", xTimes);//折线图横轴
		model.put("yValue", yValue);//折线图纵轴
		model.put("xValue",xValue );//柱状图横轴
		model.put("yShifts", yShifts);//柱状图纵轴
		model.put("shifts",allShift );
		model.put("pieDValue", pieDValue);
		model.put("pieFValue", pieFValue);
		model.put("pieLendge", pieLendge);
		model.put("path", path);
		
	}

	/**
	 * 单机电度电费周分析
	 * @param equId
	 * @param belongYear：2016
	 * @param startWeek:1
	 * @param endWeek:15
	 * @param model
	 */
	@Override
	public void getElectricityWeekData(int equId, int belongYear,
			int startWeek, int endWeek, Map<String, Object> model) {
		DecimalFormat  decf=new DecimalFormat ("0.0");
		//饼图的相关前台显示
		List<String> pieLendge=new ArrayList<String>();
		List<Map<String,Object>> pieDValue=new ArrayList<Map<String,Object>>();
		List<Map<String,Object>> pieFValue=new ArrayList<Map<String,Object>>();
		//柱状图的相关前台显示
		List<Integer> weeks=new ArrayList<Integer>();//周
		List<String> xLendge=new ArrayList<String>();
		List<Map<String,Object>> yValue=new ArrayList<Map<String,Object>>();
		xLendge.add("电度");
		Equipment equ=equipmentDao.get(equId);
		String equName=equ.getEquName();
		String equNo=equ.getEquNo();
		String photoPath=equ.getEquPhoto();
		String path="";
		if(photoPath!=null){
			path="/wz_ems/up/"+photoPath;
		}else{
			path="/wz_ems/resources/img/p1.png";
		}
		double totalCharge=0.0;
		double totalComp=0.0;
		double totalDuration=0.0;
		//查询周区间内的所有电度类型
		List<ChargeWeek> types=chargeWeekDao.getDistinctChargeName(belongYear, startWeek, endWeek);
		if(types.size()>0){
			totalDuration=stateWeekDao.getdurationByStateAndDate(equId, belongYear,  startWeek,  endWeek,"满载").getDuration();//满载总时长
			//柱状图的第一类电度数据
			List<Double> dd=new ArrayList<Double>();
			Map<String,Object> ymap=new HashMap<String,Object>();
			for(int i=startWeek;i<=endWeek;i++){
				ChargeWeek charge=chargeWeekDao.getCompByDate(equId, belongYear, i,"N");
				dd.add(charge.getRelativeComp());
				weeks.add(i);
			}
			ymap.put("name", "电度");
			ymap.put("value",dd);
			yValue.add(ymap);
			for(ChargeWeek e:types){
				Map<String,Object> Dmap=new HashMap<String,Object>();
				Map<String,Object> Fmap=new HashMap<String,Object>();
				pieLendge.add(e.getChargeName()+"电度");
				pieLendge.add(e.getChargeName()+"电费");
				xLendge.add(e.getChargeName()+"电费");
				//查询饼状图内所有不同类型的电度电费的累积值
				ChargeWeek charge=chargeWeekDao.getDurationByChargeNameAndDate(equId, belongYear, startWeek, endWeek, e.getChargeName(),"N");
				double chargeByType=charge.getCharge();
				double compByType=charge.getRelativeComp();
				Dmap.put("name", e.getChargeName()+"电度");
				Dmap.put("value", compByType);
				Fmap.put("name", e.getChargeName()+"电费");
				Fmap.put("value",chargeByType);
				pieDValue.add(Dmap);
				pieFValue.add(Fmap);
				totalCharge +=chargeByType;
				totalComp +=compByType;
				//查询柱状图每周不同类型电费使用值
				List<Double> df=new ArrayList<Double>();
				List<ChargeWeek> dfs=chargeWeekDao.getChargeByDates(equId, belongYear, startWeek, endWeek,e.getChargeName(),"N");
				int j = 0;
				for(int k=startWeek;k<=endWeek;k++){
					Double tempCharge = 0d;
					if(j<dfs.size()){
						ChargeWeek cm = dfs.get(j);
						while(cm.getBelongWeek()==k){
							tempCharge = cm.getCharge();
							j++;
							break;
						}
					}
					if(tempCharge!=0d){
						df.add(tempCharge);
					}else{
						df.add(0.0);
					}
				}
				ymap=new HashMap<String,Object>();
				ymap.put("name", e.getChargeName()+"电费");
				ymap.put("value",df);
				yValue.add(ymap);
			}
			model.put("success", true);
		}else{
			model.put("success", false);
			model.put("msg", "无数据，请重新选择时间区间");
		}
		model.put("totalCharge", Double.parseDouble(decf.format(totalCharge))+"元");
		model.put("totalComp", Double.parseDouble(decf.format(totalComp))+"度");
		model.put("totalDuration", Double.parseDouble(decf.format(totalDuration/60/60))+"小时");
		model.put("equName", equName);
		model.put("equNo", equNo);
		model.put("startTime", belongYear+"年"+startWeek+"周");
		model.put("endTime", belongYear+"年"+endWeek+"周");
		model.put("pieLendge", pieLendge);
		model.put("pieDValue",pieDValue);
		model.put("pieFValue", pieFValue);
		model.put("weeks", weeks);
		model.put("xLendge", xLendge);
		model.put("yValue", yValue);
		model.put("path", path);
	}

	/**
	 * 单机电度电费月分析
	 * @param equId
	 * @param year:2016
	 * @param startMonth:1
	 * @param endMonth:8
	 * @param model
	 */
	@Override
	public void getElectricityMonthData(int equId, int year, int startMonth,
			int endMonth, Map<String, Object> model) {
		DecimalFormat  decf=new DecimalFormat ("0.0");
		//饼图的相关前台显示
		List<String> pieLendge=new ArrayList<String>();
		List<Map<String,Object>> pieDValue=new ArrayList<Map<String,Object>>();
		List<Map<String,Object>> pieFValue=new ArrayList<Map<String,Object>>();
		//柱状图的相关前台显示
		List<String> months=new ArrayList<String>();//周
		List<String> xLendge=new ArrayList<String>();
		List<Map<String,Object>> yValue=new ArrayList<Map<String,Object>>();
		//获取准确格式的日期
		String startTime="";String endTime="";
		if(startMonth<10){
			startTime=year+"-"+"0"+startMonth;
		}else{
			startTime=year+"-"+startMonth;
		}
		if(endMonth<10){
			endTime=year+"-"+"0"+endMonth;
		}else{
			endTime=year+"-"+endMonth;
		}
		//前台显示的几个数据
		Equipment equ=equipmentDao.get(equId);
		String equName=equ.getEquName();
		String equNo=equ.getEquNo();
		String photoPath=equ.getEquPhoto();
		String path="";
		if(photoPath!=null){
			path="/wz_ems/up/"+photoPath;
		}else{
			path="/wz_ems/resources/img/p1.png";
		}
		double totalDuration=0.0;
		double totalCharge=0.0;
		double totalComp=0.0;
		//获取月区间里所有的chargeName
		List<ChargeMonth> list=chargeMonthDao.getDistinctChargeName(startTime, endTime);
		if(list.size()>0){
			totalDuration=monthDao.getTotalWorkTime(equId, startTime, endTime,"满载");//满载总时长
			//获取柱状图yValue的电度部分数据
			List<Double> dd=new ArrayList<Double>();
			xLendge.add("电度");
			Map<String,Object> ymap=new HashMap<String,Object>();
			for(int j=startMonth;j<=endMonth;j++){
				String time="";
				if(j<10){
					time=year+"-"+"0"+j;
				}else{
					time=year+"-"+j;
				}
				ChargeMonth m=chargeMonthDao.getCompByDate(equId, time, "","N");
				dd.add(m.getRelativeComp());
				months.add(time);
			}
			ymap.put("name", "电度");
			ymap.put("value",dd);
			yValue.add(ymap);
			for(ChargeMonth e:list){
				String belongTime="";
				Map<String,Object> Dmap=new HashMap<String,Object>();
				Map<String,Object> Fmap=new HashMap<String,Object>();
				pieLendge.add(e.getChargeName()+"电度");
				pieLendge.add(e.getChargeName()+"电费");
				xLendge.add(e.getChargeName()+"电费");
				//查询饼状图在相同类型的条件下，时间区间内总共消耗的电度电费值
				ChargeMonth charge=chargeMonthDao.getDurationByChargeNameAndDate(equId, startTime,endTime, e.getChargeName(), "N");
				double chargeByType=charge.getCharge();
				double compByType=charge.getRelativeComp();
				Dmap.put("name", e.getChargeName()+"电度");
				Dmap.put("value", compByType);
				Fmap.put("name", e.getChargeName()+"电费");
				Fmap.put("value",chargeByType);
				pieDValue.add(Dmap);
				pieFValue.add(Fmap);
				totalCharge +=chargeByType;
				totalComp +=compByType;
				//查询柱状图yValue类型相同情况下各周的电费使用值
				List<Double> df=new ArrayList<Double>();
				for(int i=startMonth;i<=endMonth;i++){
					if(i<10){
						belongTime=year+"-"+"0"+i;
					}else{
						belongTime=year+"-"+i;
					}
					ChargeMonth cm=chargeMonthDao.getChargeMonth(equId, belongTime, e.getChargeName(), "N");
					if(cm!=null){
						df.add(cm.getCharge());
					}else{
						df.add(0.0);
					}
				}
				ymap=new HashMap<String,Object>();
				ymap.put("name", e.getChargeName()+"电费");
				ymap.put("value",df);
				yValue.add(ymap);
				
			}
			model.put("success", true);
		}else{
			model.put("success", false);
			model.put("msg", "无数据，请重新选择时间区间");
		}
		model.put("totalCharge", Double.parseDouble(decf.format(totalCharge))+"元");
		model.put("totalComp", Double.parseDouble(decf.format(totalComp))+"度");
		model.put("totalDuration", Double.parseDouble(decf.format(totalDuration/60/60))+"小时");
		model.put("equName", equName);
		model.put("equNo", equNo);
		model.put("startTime", year+"年"+startMonth+"月");
		model.put("endTime", year+"年"+endMonth+"月");
		model.put("pieLendge", pieLendge);
		model.put("pieDValue",pieDValue);
		model.put("pieFValue", pieFValue);
		model.put("months", months);
		model.put("xLendge", xLendge);
		model.put("yValue", yValue);
		model.put("path", path);
	}

	/**
	 * 单机电度电费月分析之月同比
	 * @param equId
	 * @param month
	 * @param model
	 */
	@Override
	public void getElectricityMonthDataBySameMonth(int equId, int month,
			Map<String, Object> model) {
		DecimalFormat  df=new DecimalFormat ("0.0");
		String belongMonth=""; 
		if(month<10){
			belongMonth="0"+month;
		}else{
			belongMonth=String.valueOf(month);
		}
		List<Double> listBySameMonth=new ArrayList<Double>();//相同月份的报警记录
		List<String> listBySameMonthLendge=new ArrayList<String>();//相同月份报警记录的lendge记录
		//获取所有月份相同的时间
		List<ChargeMonth> dates=chargeMonthDao.getdistinctDate(equId, belongMonth,"N");
		if(dates.size()>0){
			for(ChargeMonth date:dates){
				ChargeMonth e=chargeMonthDao.getCompByDate(equId, date.getBelongDate(), "", "N");
				listBySameMonth.add(Double.parseDouble(df.format(e.getRelativeComp())));
				listBySameMonthLendge.add(date.getBelongDate());
			}
		}
		model.put("listBySameMonth",listBySameMonth);//月度同比报警时长(分钟)
		model.put("listBySameMonthLendge", listBySameMonthLendge);//月度同比横轴
	}

	/**
	 * 电度电费日综合分析
	 */
	@Override
	public void getElectricityCompexData(int lineId, int equId,
			String startDate, String endDate, Map<String, Object> model) {
		SimpleDateFormat sdft = new SimpleDateFormat("yyyy-MM-dd");
		DecimalFormat  df=new DecimalFormat ("0.0");
		//pie数据
		List<String> pieLendge=new ArrayList<String>();
		List<Map<String,Object>> pieDValue=new ArrayList<Map<String,Object>>();
		List<Map<String,Object>> pieFValue=new ArrayList<Map<String,Object>>();
		//bar数据
		List<String> ledge=new ArrayList<String>();//
		List<String> days=new ArrayList<String>();//
		List<Map<String,Object>> eachDayValue=new ArrayList<Map<String,Object>>();
		//pieByShift
		List<Map<String,Object>> totalCompByShift=new ArrayList<Map<String,Object>>();
		List<Map<String,Object>> totalChargeByShift=new ArrayList<Map<String,Object>>();
		Equipment equ=equipmentDao.get(equId);
		String equName=equ.getEquName();
		String equNo=equ.getEquNo();
		String photoPath=equ.getEquPhoto();
		String path="";
		if(photoPath!=null){
			path="/wz_ems/up/"+photoPath;
		}else{
			path="/wz_ems/resources/img/p1.png";
		}
		double totalComp=0.0;
		double totalCharge=0.0;
		double totalDuration=0.0;//满载总时长
		try {
			//判断时间区间是否跨班制
			ShiftConfig e=shiftConfigDao.findShiftsByTime(lineId, startDate, endDate);
			if(e!=null){
				//查询所有的班次
				List<ShiftConfig> shifts=shiftConfigDao.findByShiftsId(e.getId());
				if(shifts!=null){
					Long t1=sdft.parse(startDate).getTime();
					Long t2=sdft.parse(endDate).getTime();
					//获取所有的天数
					for(long i=t1;i<=t2;i+=86400000){
						String sd = sdft.format(new Date(i)); 
						days.add(sd);
					}
					//显示班次相同条件下，每天的电度、电费使用记录
					for(ShiftConfig shift:shifts){
						List<Double> eachCompList=new ArrayList<Double>();
						Map<String, Object> eachCompMap=new HashMap<String, Object>();
						Map<String,Object> eachChargeMap=new HashMap<String,Object>();
						ledge.add(shift.getShiftName());
						double eachTotalCharge=0.0;//时间区间内，相同班次总共的使用电费
						for(String date:days){
							String strT=shiftConfigDao.gettime(shift, date);
							String[] a=strT.split("\\|");
							String time1=a[0];
							String time2=a[1];
							ChargeMin min=chargeMinDao.getDurationByTime(equId, time1, time2);
							double relativeComp=min.getRelativeComp();
							double charge=min.getCharge();
							eachCompList.add(Double.parseDouble(df.format(relativeComp)));
							eachTotalCharge+=charge;
						}
						eachCompMap.put("name",shift.getShiftName());
						eachCompMap.put("value", eachCompList);
						eachDayValue.add(eachCompMap);
						eachChargeMap.put("name", shift.getShiftName());
						eachChargeMap.put("value", Double.parseDouble(df.format(eachTotalCharge)));
						totalChargeByShift.add(eachChargeMap);
					}
					totalCompByShift=testAddMap(eachDayValue);
					//电度电费饼状图的相关数据
					List<ChargeDay> chargeNames=chargeDayDao.getDistricChargeName(equId, startDate, endDate, "N");
					if(chargeNames.size()>0){
						for(ChargeDay name:chargeNames){
							Map<String,Object> Dmap=new HashMap<String,Object>();
							Map<String,Object> Fmap=new HashMap<String,Object>();
							String chargeName=name.getChargeName();
							pieLendge.add(chargeName+"电度");
							pieLendge.add(chargeName+"电费");
							ChargeDay chargeDay=chargeDayDao.getCompAndChargeByType(equId, startDate, endDate, name.getChargeName(), "N");
							Dmap.put("name", chargeName+"电度");
							Dmap.put("value", chargeDay.getRelativeComp());
							Fmap.put("name", chargeName+"电费");
							Fmap.put("value",chargeDay.getCharge());
							pieDValue.add(Dmap);
							pieFValue.add(Fmap);
							totalComp+=chargeDay.getRelativeComp();
							totalCharge+=chargeDay.getCharge();
						}
					}
					totalDuration=stateDayDao.getTotalWorkTime(equId, startDate, endDate,"满载");
					
					model.put("success", true);
				}else{//班制内没有班次
					model.put("success", false);
					model.put("msg", "该生产线无班次信息，请在基础模块配置");
				}
			}else{//时间区间跨班制
				model.put("success", false);
				model.put("msg", "该生产线无班制信息，请在基础模块配置");
			}
			model.put("equName", equName);
			model.put("equNo", equNo);
			model.put("startTime", startDate);
			model.put("totalCharge", Double.parseDouble(df.format(totalCharge))+"元");
			model.put("totalComp", Double.parseDouble(df.format(totalComp))+"度");
			model.put("totalDuration", Double.parseDouble(df.format(totalDuration/60/60))+"小时");
			model.put("endTime", endDate);
			model.put("pieLendge", pieLendge);
			model.put("pieDValue", pieDValue);
			model.put("pieFValue", pieFValue);
			model.put("ledge", ledge);
			model.put("days", days);
			model.put("eachDayValue", eachDayValue);
			model.put("totalCompByShift", totalCompByShift);
			model.put("totalChargeByShift", totalChargeByShift);
			model.put("path", path);
		} catch (ParseException e) {
			e.printStackTrace();
		}
		
		
	}

	/**
	 * 单机开动率日分析
	 * @param lineId
	 * @param equId
	 * @param belongDate
	 * @param model
	 */
	@Override
	public void getStartrateDayData(int lineId, int equId, String belongDate,
			Map<String, Object> model) {
		SimpleDateFormat sdft = new SimpleDateFormat("yyyy-MM-dd HH:mm");
		SimpleDateFormat formatter = new SimpleDateFormat("HH:mm");
		DecimalFormat  df=new DecimalFormat ("0.0");
		//班次满载率
		List<String> shiftList=new ArrayList<String>();
		List<Double> rates=new ArrayList<Double>();
		//饼状图的能耗和状态信息
		List<String> stateTypes=new ArrayList<String>();
		List<Map<String,Object>> pieSValue=new ArrayList<Map<String,Object>>();
		List<Map<String,Object>> pieDValue=new ArrayList<Map<String,Object>>();
		//柱状图的时刻信息
		List<String> xTimes=Arrays.asList(new String[]{"00:30", "01:00", "01:30", "02:00", "02:30", "03:00", "03:30", "04:00", "04:30", "05:00", "05:30", "06:00", "06:30", "07:00", "07:30", "08:00", "08:30", "09:00", "09:30", "10:00", "10:30", "11:00", "11:30", "12:00", "12:30", "13:00", "13:30", "14:00", "14:30", "15:00", "15:30", "16:00", "16:30", "17:00", "17:30", "18:00", "18:30", "19:00", "19:30", "20:00", "20:30", "21:00", "21:30", "22:00", "22:30", "23:00", "23:30", "24:00"});//getXAxis();
		List<Map<String,Object>> yValues=new ArrayList<Map<String,Object>>();
		//其他
		List<String> shiftss=new ArrayList<String>();
		double totalComp=0.0;
		double totalDuration=0.0;
		Equipment equ=equipmentDao.get(equId);
	    String equName=equ.getEquName();
	    String equNo=equ.getEquNo();
	    String photoPath=equ.getEquPhoto();
		String path="";
		if(photoPath!=null){
			path="/wz_ems/up/"+photoPath;
		}else{
			path="/wz_ems/resources/img/p1.png";
		}
		try {
			//班制
			ShiftConfig  config=shiftConfigDao.findShiftsByLine(lineId, belongDate);
			if(config!=null){
				List<ShiftConfig> shifts=shiftConfigDao.findByShiftsId(config.getId());
				if(shifts.size()>0){
					//班次信息满载率(横向柱状图)
					for(ShiftConfig shift:shifts){
						shiftss.add(shift.getShiftName());
						shiftList.add(shift.getShiftName());
						String strT=shiftConfigDao.gettime(shift, belongDate);
						String[] a=strT.split("\\|");
						String time1=a[0];
						String time2=a[1];
						Long t1=sdft.parse(time1).getTime();
						Long t2=sdft.parse(time2).getTime();
						//班次总时长（s）
						double total=(double) ((t2-t1)/1000);
						//班次满载总时长
						double duration=stateMinDao.getDurationByTime(equId, "满载", time1, time2);
						double f=Double.parseDouble(df.format((duration/total)*100));
						totalDuration+=duration;
						rates.add(f);
					}
					rates.add(Double.parseDouble(df.format(totalDuration/(24*60*60)*100)));
					shiftList.add("全天");
					//饼状图的状态信息(饼状图)
					List<StateDay> list=stateDayDao.getStateDayByDate(equId, belongDate);
					if(list.size()>0){
						for(StateDay entity:list){
							Map<String,Object> sMap=new HashMap<String,Object>();
							Map<String,Object> dMap=new HashMap<String,Object>();
							List<Double> yValue=new ArrayList<Double>();
							Map<String,Object> yMap=new HashMap<String,Object>();
							
							String type=entity.getStateType();
							double duration=entity.getDuration();
							double relativeComp=entity.getRelativeComp();
							stateTypes.add(type);
							sMap.put("name", type);
							sMap.put("value", Double.parseDouble(df.format(duration/60)));
							pieSValue.add(sMap);
							dMap.put("name", type);
							dMap.put("value", relativeComp);
							pieDValue.add(dMap);
							totalComp+=relativeComp;
							//柱状图信息
							List<StateMin> minList=stateMinDao.getStateMinsByDay(equId, type, belongDate);
							int i = 0;
							for(String xt:xTimes){
								Double temp = 0d;
								if(i<minList.size()){
									StateMin cm = minList.get(i);
									if(formatter.format(cm.getBelongTime()).equals("00:00")){
										i++;
									}else{
										while(formatter.format(cm.getBelongTime()).equals(xt)){
											temp = Double.parseDouble(df.format(cm.getDuration()/60));
											i++;
											break;
										}
									}
								}
								if(temp!=0d){
									yValue.add(temp);
								}else{
									yValue.add(0.0);
								}
							}
							yMap.put("name", entity.getStateType());
							yMap.put("value", yValue);
							yValues.add(yMap);
						}
					}else{
						//在无记录的情况下，给柱状图赋值
						List<EquStateConfig> stateList=equStateConfigDao.getDistinctType();
						for(EquStateConfig entity:stateList){
							stateTypes.add(entity.getStateType());
							Map<String,Object> yMap=new HashMap<String,Object>();
							List<Double> yValue=new ArrayList<Double>();
							for(int i=0;i<xTimes.size();i++){
								yValue.add(0.0);
							}
							yMap.put("name", entity.getStateType());
							yMap.put("value", yValue);
							yValues.add(yMap);
							//无记录情况下给饼状图赋值
							Map<String,Object> sMap1=new HashMap<String,Object>();
							Map<String,Object> dMap1=new HashMap<String,Object>();
							sMap1.put("name", entity.getStateType());
							sMap1.put("value", 0);
							pieSValue.add(sMap1);
							dMap1.put("name", entity.getStateType());
							dMap1.put("value", 0);
							pieDValue.add(dMap1);
						}
					}
					model.put("success", true);
				}else{
					model.put("success", false);
					model.put("msg", "该生产线无班次信息，请在基础模块配置");
				}
			}else{
				model.put("success", false);
				model.put("msg", "该生产线无班制信息，请在基础模块配置");
			}
			model.put("shiftList", shiftList);
			model.put("rates",rates );
			model.put("stateTypes", stateTypes);
			model.put("pieSValue", pieSValue);
			model.put("pieDValue", pieDValue);
			model.put("xTimes", xTimes);
			model.put("yValue", yValues);
			model.put("belongDate", belongDate);
			model.put("equName", equName);
			model.put("equNo", equNo);
			model.put("shiftss", shiftss);
			model.put("totalComp", Double.parseDouble(df.format(totalComp))+"度");
			model.put("equName", equName);
			model.put("equNo", equNo);
			model.put("belongDate", belongDate);
			model.put("path", path);
		} catch (NumberFormatException e) {
			e.printStackTrace();
		} catch (ParseException e) {
			e.printStackTrace();
		}
	}

	/**
	 * 开动率日综合分析
	 * @param lineId
	 * @param equId
	 * @param startDate
	 * @param endDate
	 * @param model
	 */
	@Override
	public void getStartrateCompexData(int lineId, int equId, String startDate,
			String endDate, Map<String, Object> model) {
		SimpleDateFormat sdft = new SimpleDateFormat("yyyy-MM-dd");
		SimpleDateFormat sdft1 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		DecimalFormat  df=new DecimalFormat ("0.0");
		//1.饼状图的状态和能耗信息
		List<String> pieLegend=new ArrayList<String>();
		List<Map<String,Object>> pieSValue=new ArrayList<Map<String,Object>>();
		List<Map<String,Object>> pieCValue=new ArrayList<Map<String,Object>>();
		//bar数据
		List<String> days=new ArrayList<String>();//日期
		List<Map<String,Object>> eachDayValue=new ArrayList<Map<String,Object>>();
		//班次满载率
		List<String> shiftList=new ArrayList<String>();
		List<Double> rates=new ArrayList<Double>();
		//满载总时长和消耗总电度
		double sumByDuration=0.0;
		double sumByComp=0.0;
		Equipment equ=equipmentDao.get(equId);
	    String equName=equ.getEquName();
	    String equNo=equ.getEquNo();
	    String photoPath=equ.getEquPhoto();
		String path="";
		if(photoPath!=null){
			path="/wz_ems/up/"+photoPath;
		}else{
			path="/wz_ems/resources/img/p1.png";
		}
		try {
			Long t1=sdft.parse(startDate).getTime();
			Long t2=sdft.parse(endDate).getTime();
			//获取所有的天数
			for(long i=t1;i<=t2;i+=86400000){
				String sd = sdft.format(new Date(i)); 
				days.add(sd);
			}
			//1.判断是否跨班制
			ShiftConfig e=shiftConfigDao.findShiftsByTime(lineId, startDate, endDate);
			if(e!=null){
				//查询所有的班次
				List<ShiftConfig> shifts=shiftConfigDao.findByShiftsId(e.getId());
				if(shifts.size()>0){
					
					List<StateDay> types=stateDayDao.getDistinctType(equId, startDate, endDate);
					if(types.size()>0){
						//获取柱状图和饼状图的相关数据
						for(StateDay type:types){
							List<Double> eachDayList=new ArrayList<Double>();
							Map<String, Object> eachDayMap=new HashMap<String, Object>();
							Map<String,Object> eachPieSMap=new HashMap<String,Object>();
							Map<String,Object> eachPieCMap=new HashMap<String,Object>();
							double typeByComp=0.0;
							double typeByDuration=0.0;
							String stateType=type.getStateType();
							pieLegend.add(stateType);
							for(String day:days){
								StateDay stateDay=stateDayDao.getStateDay(equId, stateType, day);
								if(stateDay!=null){
									double duration=stateDay.getDuration();
									double comp=stateDay.getRelativeComp();
									typeByComp+=comp;
									typeByDuration+=duration;
									eachDayList.add(Double.parseDouble(df.format(duration/60)));
									if(stateType.equals("满载")){
										sumByDuration+=duration;
									}
									sumByComp+=comp;
								}else{
									eachDayList.add(0.0);
								}
							}
							eachDayMap.put("name", stateType);
							eachDayMap.put("value", eachDayList);
							eachDayValue.add(eachDayMap);
							eachPieSMap.put("name", stateType);
							eachPieSMap.put("value", Double.parseDouble(df.format(typeByDuration/60)));
							pieSValue.add(eachPieSMap);
							eachPieCMap.put("name", stateType);
							eachPieCMap.put("value", Double.parseDouble(df.format(typeByComp)));
							pieCValue.add(eachPieCMap);
							
						}
						//获取不同班次的满载率相关数据(横向柱状图)
						double totalDurationByType=0.0;
						int d=days.size();
						for(ShiftConfig shift:shifts){
							shiftList.add(shift.getShiftName());
							String strT=shiftConfigDao.gettime(shift, startDate);
							String[] a=strT.split("\\|");
							String time1=a[0];
							String time2=a[1];
							Long st1=sdft1.parse(time1).getTime();
							Long st2=sdft1.parse(time2).getTime();
							//班次总时长（s）
							double total=(double) ((st2-st1)*d/1000);
							//班次满载总时长
							double duration=stateShiftDao.getDurationByShiftAndType(equId, "满载", shift.getShiftName(), startDate, endDate);
							double f=Double.parseDouble(df.format((duration/total)*100));
							totalDurationByType+=duration;
							rates.add(f);
						}
						shiftList.add("全天");
						double ds=d*24*60*60;
						rates.add(Double.parseDouble(df.format((totalDurationByType/ds)*100)));
						model.put("success", true);
					}else{
						model.put("success", false);
						model.put("msg", "无实时数据生成，请重新选择时间");
					}
				}else{
					model.put("success", false);
					model.put("msg", "该生产线无班次信息，请在基础模块配置");
				}
			}else{
				model.put("success", false);
				model.put("msg", "该生产线无班制信息，请在基础模块配置");
			}
			model.put("equName", equName);
			model.put("equNo", equNo);
			model.put("startTime", startDate);
			model.put("endTime", endDate);
			model.put("sumByDuration", Double.parseDouble(df.format(sumByDuration/60))+"分钟");
			model.put("sumByComp", Double.parseDouble(df.format(sumByComp))+"度");
			model.put("shiftList", shiftList);
			model.put("rates", rates);
			model.put("eachDayValue", eachDayValue);
			model.put("days", days);
			model.put("pieLegend", pieLegend);
			model.put("pieSValue", pieSValue);
			model.put("pieCValue", pieCValue);
			model.put("path", path);
		} catch (ParseException e) {
			e.printStackTrace();
		}
	}

	/**
	 * 开动率周分析
	 * @param equId
	 * @param belongYear
	 * @param startWeek
	 * @param endWeek
	 * @param model
	 */
	@Override
	public void getStartrateWeekData(int equId, int belongYear, int startWeek,
			int endWeek, Map<String, Object> model) {
		DecimalFormat  df=new DecimalFormat ("0.0");
		//饼状图的状态和能耗信息
		List<String> pieLegend=new ArrayList<String>();
		List<Map<String,Object>> pieSValue=new ArrayList<Map<String,Object>>();
		List<Map<String,Object>> pieCValue=new ArrayList<Map<String,Object>>();
		//bar数据
		List<Integer> weeks=new ArrayList<Integer>();//周
		List<Map<String,Object>> eachDayValue=new ArrayList<Map<String,Object>>();
		Equipment equ=equipmentDao.get(equId);
		String equName=equ.getEquName();
		String equNo=equ.getEquNo();
		String photoPath=equ.getEquPhoto();
		String path="";
		if(photoPath!=null){
			path="/wz_ems/up/"+photoPath;
		}else{
			path="/wz_ems/resources/img/p1.png";
		}
		double sumByDuration=0.0;
		double sumByComp=0.0;
		//周
		for(int m=startWeek;m<=endWeek;m++){
			weeks.add(m);
		}
		//判断周内的所有状态类型
		List<StateWeek> types=stateWeekDao.getDistinctType(equId, belongYear, startWeek, endWeek);
		if(types.size()>0){
			for(StateWeek type:types){
				List<Double> eachDayList=new ArrayList<Double>();
				Map<String, Object> eachDayMap=new HashMap<String, Object>();
				Map<String,Object> eachPieSMap=new HashMap<String,Object>();
				Map<String,Object> eachPieCMap=new HashMap<String,Object>();
				String stateType=type.getStateType();
				pieLegend.add(stateType);
				//获取该状态下周区间的电度电费总消耗值(饼状图)
				StateWeek week=stateWeekDao.getdurationByStateAndDate(equId, belongYear, startWeek, endWeek, stateType);
				eachPieSMap.put("name", stateType);
				eachPieSMap.put("value", Double.parseDouble(df.format(week.getDuration()/60/60)));
				pieSValue.add(eachPieSMap);
				eachPieCMap.put("name", stateType);
				eachPieCMap.put("value", Double.parseDouble(df.format(week.getRelativeComp())));
				pieCValue.add(eachPieCMap);
				//满载总时长赋值
				if(stateType.equals("满载")){
					sumByDuration=week.getDuration();
				}
				//所有状态使用电度累加值
				sumByComp+=week.getRelativeComp();
				//获取周区间内的状态记录值(柱状图)
				List<StateWeek> stateWeeks=stateWeekDao.getStateWeekByStateAndDates(equId, stateType, belongYear, startWeek, endWeek);
				int i = 0;
				for(int xt:weeks){
					Double temp = 0d;
					if(i<stateWeeks.size()){
						StateWeek cm = stateWeeks.get(i);
						while(cm.getBelongWeek().equals(xt)){
							temp = Double.parseDouble(df.format(cm.getDuration()/60));
							i++;
							break;
						}
					}
					if(temp!=0d){
						eachDayList.add(temp);
					}else{
						eachDayList.add(0.0);
					}
				}
				eachDayMap.put("name", stateType);
				eachDayMap.put("value", eachDayList);
				eachDayValue.add(eachDayMap);
			}
			model.put("success", true);
		}else{
			model.put("success", false);
			model.put("msg", "无数据，请重新选择时间区间");
		}
		model.put("sumByComp", Double.parseDouble(df.format(sumByComp))+"度");
		model.put("sumByDuration", Double.parseDouble(df.format(sumByDuration/60/60))+"小时");
		model.put("equName", equName);
		model.put("equNo", equNo);
		model.put("startTime", belongYear+"年"+startWeek+"周");
		model.put("endTime", belongYear+"年"+endWeek+"周");
		model.put("pieLegend", pieLegend);
		model.put("pieSValue",pieSValue);
		model.put("pieCValue", pieCValue);
		model.put("weeks", weeks);
		model.put("eachDayValue", eachDayValue);
		model.put("path", path);
	}

	/**
	 * 开动率月分析
	 * @param equId
	 * @param year
	 * @param startMonth
	 * @param endMonth
	 * @param model
	 */
	@Override
	public void getStartrateMonthData(int equId, int year, int startMonth,
			int endMonth, Map<String, Object> model) {
		DecimalFormat  df=new DecimalFormat ("0.0");
		String startTime="";
		String endTime="";
		if(startMonth<10){
			startTime=year+"-"+"0"+startMonth;
		}else{
			startTime=year+"-"+startMonth;
		}
		if(endMonth<10){
			endTime=year+"-"+"0"+endMonth;
		}else{
			endTime=year+"-"+endMonth;
		}
		//1.饼状图的状态和能耗信息
		List<String> pieLegend=new ArrayList<String>();
		List<Map<String,Object>> pieSValue=new ArrayList<Map<String,Object>>();
		List<Map<String,Object>> pieCValue=new ArrayList<Map<String,Object>>();
		//bar数据
		List<Integer> months=new ArrayList<Integer>();//周
		List<Map<String,Object>> eachDayValue=new ArrayList<Map<String,Object>>();
		//其他
		Equipment equ=equipmentDao.get(equId);
		String equName=equ.getEquName();
		String equNo=equ.getEquNo();
		String photoPath=equ.getEquPhoto();
		String path="";
		if(photoPath!=null){
			path="/wz_ems/up/"+photoPath;
		}else{
			path="/wz_ems/resources/img/p1.png";
		}
		double sumByDuration=0.0;
		double sumByComp=0.0;
		//月
		for(int i=startMonth;i<=endMonth;i++){
			months.add(i);
		}
		//1.判断月内的所有状态类型
		List<StateMonth> types=monthDao.getDistinctType(equId, startTime, endTime);
		if(types.size()>0){
			for(StateMonth type:types){
				String stateType=type.getStateType();
				pieLegend.add(stateType);
				List<Double> eachDayList=new ArrayList<Double>();
				Map<String, Object> eachDayMap=new HashMap<String, Object>();
				Map<String,Object> eachPieSMap=new HashMap<String,Object>();
				Map<String,Object> eachPieCMap=new HashMap<String,Object>();
				//饼状图
				StateMonth month=monthDao.getDurationByTypeAndDate(equId, startTime, endTime, stateType);
				eachPieSMap.put("name", stateType);
				eachPieSMap.put("value", Double.parseDouble(df.format(month.getDuration()/60/60)));
				pieSValue.add(eachPieSMap);
				eachPieCMap.put("name", stateType);
				eachPieCMap.put("value", Double.parseDouble(df.format(month.getRelativeComp())));
				pieCValue.add(eachPieCMap);
				//满载总时长赋值
				if(stateType.equals("满载")){
					sumByDuration=month.getDuration();
				}
				//所有状态使用电度累加值
				sumByComp+=month.getRelativeComp();
				//状态时长(柱状图)
				List<StateMonth> stateMonthList=monthDao.getStateMonthByStateAndDates(equId, startTime, endTime, stateType);
				int i=0;
				for(int k=startMonth;k<=endMonth;k++){
					Double temp = 0d;
					if(i<stateMonthList.size()){
						StateMonth cm = stateMonthList.get(i);
						while(Integer.parseInt(cm.getBelongDate().substring(5))==k){
							temp = Double.parseDouble(df.format(cm.getDuration()/60/60));
							i++;
							break;
						}
					}
					if(temp!=0d){
						eachDayList.add(temp);
					}else{
						eachDayList.add(0.0);
					}
				}
				eachDayMap.put("name", stateType);
				eachDayMap.put("value", eachDayList);
				eachDayValue.add(eachDayMap);
			}
			model.put("success", true);
		}else{
			model.put("success", false);
			model.put("msg", "无数据，请重新选择时间区间");
		}
		model.put("sumByComp", Double.parseDouble(df.format(sumByComp))+"度");
		model.put("sumByDuration", Double.parseDouble(df.format(sumByDuration/60/60))+"小时");
		model.put("equName", equName);
		model.put("equNo", equNo);
		model.put("startTime", year+"年"+startMonth+"月");
		model.put("endTime", year+"年"+endMonth+"月");
		model.put("pieLegend", pieLegend);
		model.put("pieSValue",pieSValue);
		model.put("pieCValue", pieCValue);
		model.put("months", months);
		model.put("eachDayValue", eachDayValue);
		model.put("path", path);
	}

	/**
	 * 开动率月分析之满载率月同比
	 * @param equId
	 * @param month
	 * @param model
	 */
	@Override
	public void getStartrateMonthDataBySameMonth(int equId, int month,
			Map<String, Object> model) {
		DecimalFormat  df=new DecimalFormat ("0.0");
		String belongMonth=""; 
		if(month<10){
			belongMonth="0"+month;
		}else{
			belongMonth=String.valueOf(month);
		}
		String stateType="满载";
		List<Double> listBySameMonth=new ArrayList<Double>();//相同月份的报警记录
		List<String> listBySameMonthLendge=new ArrayList<String>();//相同月份报警记录的lendge记录
		//获取所有月份相同的记录
		List<StateMonth> list=monthDao.getBySameMonth(equId, belongMonth, stateType);
		if(list.size()>0){
			for(StateMonth entity:list){
				//获取当前年份当前月的所有天数
				String time=entity.getBelongDate();
				int belongY=Integer.parseInt(time.substring(0,4));
				int belongM=Integer.parseInt(time.substring(5));
				Calendar a = Calendar.getInstance();  
		        a.set(Calendar.YEAR, belongY);  
		        a.set(Calendar.MONTH, belongM - 1);  
		        a.set(Calendar.DATE, 1);  
		        a.roll(Calendar.DATE, -1);  
		        int maxDate = a.get(Calendar.DATE);  
				double duration=entity.getDuration();
				double ds=maxDate*24*60*60;
				listBySameMonthLendge.add(entity.getBelongDate());
				listBySameMonth.add(Double.parseDouble(df.format((duration/ds)*100)));
			}
		}
		model.put("listBySameMonth",listBySameMonth);//月度同比报警时长(分钟)
		model.put("listBySameMonthLendge", listBySameMonthLendge);//月度同比横轴
	}

	@Override
	public void getComprehensiveDayData(int lineId, int equId,
			String belongDate, Map<String, Object> model) {
		SimpleDateFormat formatter = new SimpleDateFormat("HH:mm");
		DecimalFormat  df=new DecimalFormat ("0.0");
		//1.电度趋势和状态时长(折线图和柱状图数据)
		List<String> xTimes=Arrays.asList(new String[]{"00:30", "01:00", "01:30", "02:00", "02:30", "03:00", "03:30", "04:00", "04:30", "05:00", "05:30", "06:00", "06:30", "07:00", "07:30", "08:00", "08:30", "09:00", "09:30", "10:00", "10:30", "11:00", "11:30", "12:00", "12:30", "13:00", "13:30", "14:00", "14:30", "15:00", "15:30", "16:00", "16:30", "17:00", "17:30", "18:00", "18:30", "19:00", "19:30", "20:00", "20:30", "21:00", "21:30", "22:00", "22:30", "23:00", "23:30", "24:00"});//getXAxis();
		List<Double> yValue_D=new ArrayList<Double>();
		List<Map<String,Object>> yValue_S=new ArrayList<Map<String,Object>>();
		
		//2.电费和状态时长(饼状图)
		List<String> pieLendge_F=new ArrayList<String>();
		List<Map<String,Object>> pieFValue=new ArrayList<Map<String,Object>>();
		List<String> pieLendge_S=new ArrayList<String>();
		List<Map<String,Object>> pieSValue=new ArrayList<Map<String,Object>>();
		//其他
		Equipment equ=equipmentDao.get(equId);
		String equNo=equ.getEquNo();
		String equName=equ.getEquName();
		String photoPath=equ.getEquPhoto();
		String path="";
		if(photoPath!=null){
			path="/wz_ems/up/"+photoPath;
		}else{
			path="/wz_ems/resources/img/p1.png";
		}
		double ratedPower=equ.getRatedPower();
		double totalCharge=0.0;//全天电费
		double totalComp=0.0;//全天电度
		double overDuration=0.0;//超载总时长
//		Double maxP_active=0.0;//最高功率
		
		ShiftConfig  config=shiftConfigDao.findShiftsByLine(lineId, belongDate);//班制
		if(config!=null){
			List<ShiftConfig> shifts=shiftConfigDao.findByShiftsId(config.getId());
			if(shifts.size()>0){
				//1.全天每半小时的电度情况(折线图)
				List<ChargeMin> list=chargeMinDao.getChargeMinsByDay(equId, belongDate,"N");
				int i = 0;
				for(String xt:xTimes){
					Double tempCharge = 0d;
					if(i<list.size()){
						ChargeMin cm = list.get(i);
						if(formatter.format(cm.getBelongTime()).equals("00:00")){
							i++;
						}else{
							while(formatter.format(cm.getBelongTime()).equals(xt)){
								tempCharge = cm.getRelativeComp();
								i++;
								break;
							}
						}
					}
					if(tempCharge!=0.0){
						yValue_D.add(tempCharge);
					}else{
						yValue_D.add(0.0);
					}
				}
				//2.获取全天电度电费信息(饼状图)
				List<ChargeDay> dayList=chargeDayDao.getChargeDayIdAndDate(equId, belongDate,"N");
				if(dayList!=null){
					Map<String,Object> fmap;
					for(ChargeDay day:dayList){
						String chargeName=day.getChargeName();
						double charge=day.getCharge();
						double comp=day.getRelativeComp();
						fmap=new HashMap<String,Object>();
						pieLendge_F.add(chargeName+"电费");
						fmap.put("name", chargeName+"电费");
						fmap.put("value", charge);
						pieFValue.add(fmap);
						totalCharge+=charge;
						totalComp+=comp;
					}
					fmap=new HashMap<String,Object>();
					pieLendge_F.add("总电费");
					fmap.put("name", "总电费");
					fmap.put("value", Double.parseDouble(df.format(totalCharge)));
					pieFValue.add(fmap);
				}
				//3.设备状态和状态时长
				List<StateDay> stateList=stateDayDao.getStateDayByDate(equId, belongDate);
				if(list.size()>0){
					for(StateDay entity:stateList){
						Map<String,Object> sMap=new HashMap<String,Object>();
						List<Double> yValue=new ArrayList<Double>();
						Map<String,Object> yMap=new HashMap<String,Object>();
						String type=entity.getStateType();
						double duration=entity.getDuration();
						pieLendge_S.add(type);
						sMap.put("name", type);
						sMap.put("value", Double.parseDouble(df.format(duration/60)));
						pieSValue.add(sMap);
						if(type.equals("超载")){
							overDuration=duration;
						}
						//4.柱状图信息
						List<StateMin> minList=stateMinDao.getStateMinsByDay(equId, type, belongDate);
						int k = 0;
						for(String xt:xTimes){
							Double temp = 0d;
							if(k<minList.size()){
								StateMin cm = minList.get(k);
								if(formatter.format(cm.getBelongTime()).equals("00:00")){
									k++;
								}else{
									while(formatter.format(cm.getBelongTime()).equals(xt)){
										temp = Double.parseDouble(df.format(cm.getDuration()/60));
										k++;
										break;
									}
								}
							}
							if(temp!=0d){
								yValue.add(temp);
							}else{
								yValue.add(0.0);
							}
						}
						yMap.put("name", entity.getStateType());
						yMap.put("value", yValue);
						yValue_S.add(yMap);
					}
				}else{
					//在无记录的情况下，给柱状图赋值
					List<EquStateConfig> stateList1=equStateConfigDao.getDistinctType();
					for(EquStateConfig entity:stateList1){
						pieLendge_S.add(entity.getStateType());
						Map<String,Object> yMap=new HashMap<String,Object>();
						List<Double> yValue=new ArrayList<Double>();
						for(int s=0;s<xTimes.size();s++){
							yValue.add(0.0);
						}
						yMap.put("name", entity.getStateType());
						yMap.put("value", yValue);
						yValue_S.add(yMap);
						//在无记录的情况下，给状态的环形图赋值
						Map<String,Object> sMap1=new HashMap<String,Object>();
						sMap1.put("name", entity.getStateType());
						sMap1.put("value", 0);
						pieSValue.add(sMap1);
					}
				}
//				maxP_active=baseDataDao.getMaxP_active(equNo, belongDate);
				model.put("success", true);
			}else{
				model.put("success", false);
				model.put("msg", "该生产线无班次信息，请在基础模块配置");
			}
		}else{
			model.put("success", false);
			model.put("msg", "该生产线无班制信息，请在基础模块配置");
		}
		model.put("xTimes", xTimes);
		model.put("yValue_D",yValue_D );
		model.put("yValue_S", yValue_S);
		model.put("pieLendge_F", pieLendge_F);
		model.put("pieFValue", pieFValue);
		model.put("pieLendge_S", pieLendge_S);
		model.put("pieSValue", pieSValue);
		model.put("totalComp", Double.parseDouble(df.format(totalComp))+"度");
		model.put("overDuration", Double.parseDouble(df.format(overDuration/60))+"分钟");
		model.put("equName", equName);
		model.put("equNo", equNo);
		model.put("ratedPower", ratedPower+"KW");
		model.put("belongDate", belongDate);
		model.put("path", path);
//		model.put("maxP_active", maxP_active+"W");
		
	}

	@Override
	public void getComprehensiveCompexData(int lineId, int equId,
			String startTime, String endTime, Map<String, Object> model) {
		SimpleDateFormat sdft = new SimpleDateFormat("yyyy-MM-dd");
		DecimalFormat  df=new DecimalFormat ("0.0");
		//1.电度趋势和状态时长(折线图和柱状图数据)
		List<String> days=new ArrayList<String>();
		List<Double> yValue_D=new ArrayList<Double>();
		List<Map<String,Object>> yValue_S=new ArrayList<Map<String,Object>>();
		//2.电费和状态时长(饼状图)
		List<String> pieLendge_F=new ArrayList<String>();
		List<Map<String,Object>> pieFValue=new ArrayList<Map<String,Object>>();
		List<String> pieLendge_S=new ArrayList<String>();
		List<Map<String,Object>> pieSValue=new ArrayList<Map<String,Object>>();
		//其他
		Equipment equ=equipmentDao.get(equId);
		String equNo=equ.getEquNo();
		String equName=equ.getEquName();
		String photoPath=equ.getEquPhoto();
		String path="";
		if(photoPath!=null){
			path="/wz_ems/up/"+photoPath;
		}else{
			path="/wz_ems/resources/img/p1.png";
		}
		double ratedPower=equ.getRatedPower();
		double totalCharge=0.0;//全天电费
		double totalComp=0.0;//全天电度
		double overDuration=0.0;//超载总时长
//		Double maxP_active=0.0;//最高功率
		try {
			ShiftConfig e=shiftConfigDao.findShiftsByTime(lineId, startTime, endTime);
			if(e!=null){
				List<ShiftConfig> shifts=shiftConfigDao.findByShiftsId(e.getId());
				if(shifts.size()>0){
					Long t1=sdft.parse(startTime).getTime();
					Long t2=sdft.parse(endTime).getTime();
					//获取所有的天数,并得到每天的电度值
					for(long i=t1;i<=t2;i+=86400000){
						String sd = sdft.format(new Date(i)); 
						days.add(sd);
						ChargeDay dayComp=chargeDayDao.getCompAndChargeByType(equId, sd, sd, "", "N");
						yValue_D.add(dayComp.getRelativeComp());
					}
					List<StateDay> types=stateDayDao.getDistinctType(equId, startTime, endTime);
					if(types.size()>0){
						//状态柱状图和饼状图的相关数据
						for(StateDay type:types){
							List<Double> eachDayList=new ArrayList<Double>();
							Map<String, Object> eachDayMap=new HashMap<String, Object>();
							Map<String,Object> eachPieSMap=new HashMap<String,Object>();
							double typeByDuration=0.0;
							String stateType=type.getStateType();
							pieLendge_S.add(stateType);
							for(String day:days){
								StateDay stateDay=stateDayDao.getStateDay(equId, stateType, day);
								if(stateDay!=null){
									double duration=stateDay.getDuration();
									typeByDuration+=duration;
									eachDayList.add(Double.parseDouble(df.format(duration/60)));
									if(stateType.equals("超载")){
										overDuration+=duration;
									}
								}else{
									eachDayList.add(0.0);
								}
							}
							eachDayMap.put("name", stateType);
							eachDayMap.put("value", eachDayList);
							yValue_S.add(eachDayMap);
							eachPieSMap.put("name", stateType);
							eachPieSMap.put("value", Double.parseDouble(df.format(typeByDuration/60)));
							pieSValue.add(eachPieSMap);
						}
					}
					//电费饼状图的相关数据
					List<ChargeDay> chargeNames=chargeDayDao.getDistricChargeName(equId, startTime, endTime, "N");
					if(chargeNames.size()>0){
						Map<String,Object> Fmap;
						for(ChargeDay name:chargeNames){
							Fmap=new HashMap<String,Object>();
							String chargeName=name.getChargeName();
							pieLendge_F.add(chargeName+"电费");
							ChargeDay chargeDay=chargeDayDao.getCompAndChargeByType(equId, startTime, endTime, name.getChargeName(), "N");
							Fmap.put("name", chargeName+"电费");
							Fmap.put("value",chargeDay.getCharge());
							pieFValue.add(Fmap);
							totalComp+=chargeDay.getRelativeComp();
							totalCharge+=chargeDay.getCharge();
						}
						Fmap=new HashMap<String,Object>();
						pieLendge_F.add("总电费");
						Fmap.put("name", "总电费");
						Fmap.put("value", Double.parseDouble(df.format(totalCharge)));
						pieFValue.add(Fmap);
					}
//					maxP_active=baseDataDao.getMaxP_activeByTimes(equNo, startTime, endTime);
					model.put("success", true);
				}else{
					model.put("success", false);
					model.put("msg", "该生产线无班次信息，请在'班次模式配置'里做好基础配置");
				}
			}else{
				model.put("success", false);
				model.put("msg", "该生产线无班制信息，请在'班次模式配置'里做好基础配置");
			}
		} catch (ParseException e) {
			e.printStackTrace();
		}
		model.put("xTimes", days);
		model.put("yValue_D",yValue_D );
		model.put("yValue_S", yValue_S);
		model.put("pieLendge_F", pieLendge_F);
		model.put("pieFValue", pieFValue);
		model.put("pieLendge_S", pieLendge_S);
		model.put("pieSValue", pieSValue);
		model.put("totalComp", Double.parseDouble(df.format(totalComp))+"度");
		model.put("overDuration", Double.parseDouble(df.format(overDuration/60))+"分钟");
		model.put("equName", equName);
		model.put("equNo", equNo);
		model.put("ratedPower", ratedPower+"KW");
		model.put("startTime", startTime);
		model.put("endTime", endTime);
		model.put("path", path);
//		model.put("maxP_active", maxP_active+"W");
		
	}

	@Override
	public void getComprehensiveWeekData(int equId, int belongYear,
			int startWeek, int endWeek, Map<String, Object> model) {
DecimalFormat  df=new DecimalFormat ("0.0");
		
		//1.电度趋势和状态时长(折线图和柱状图数据)
		List<Integer> weeks=new ArrayList<Integer>();
		List<Double> yValue_D=new ArrayList<Double>();
		List<Map<String,Object>> yValue_S=new ArrayList<Map<String,Object>>();
		//2.电费和状态时长(饼状图)
		List<String> pieLendge_F=new ArrayList<String>();
		List<Map<String,Object>> pieFValue=new ArrayList<Map<String,Object>>();
		List<String> pieLendge_S=new ArrayList<String>();
		List<Map<String,Object>> pieSValue=new ArrayList<Map<String,Object>>();
		//其他
		Equipment equ=equipmentDao.get(equId);
		String equNo=equ.getEquNo();
		String equName=equ.getEquName();
		String photoPath=equ.getEquPhoto();
		String path="";
		if(photoPath!=null){
			path="/wz_ems/up/"+photoPath;
		}else{
			path="/wz_ems/resources/img/p1.png";
		}
		double ratedPower=equ.getRatedPower();
		double totalCharge=0.0;//全天电费
		double totalComp=0.0;//全天电度
		double overDuration=0.0;//超载总时长
//		Double maxP_active=0.0;//最高功率
		//查询周区间内的所有电度类型
		List<ChargeWeek> types=chargeWeekDao.getDistinctChargeName(belongYear, startWeek, endWeek);
		if(types.size()>0){
			overDuration=stateWeekDao.getdurationByStateAndDate(equId, belongYear,  startWeek,  endWeek,"超载").getDuration();//超载总时长
			//1电度趋势(折线图)
			for(int i=startWeek;i<=endWeek;i++){
				ChargeWeek charge=chargeWeekDao.getCompByDate(equId, belongYear, i,"N");
				yValue_D.add(charge.getRelativeComp());
				weeks.add(i);
			}
			//2电费饼状图
			Map<String,Object> Fmap;
			for(ChargeWeek e:types){
				Fmap=new HashMap<String,Object>();
				pieLendge_F.add(e.getChargeName()+"电费");
				//查询饼状图内所有不同类型的电度电费的累积值
				ChargeWeek charge=chargeWeekDao.getDurationByChargeNameAndDate(equId, belongYear, startWeek, endWeek, e.getChargeName(),"N");
				double chargeByType=charge.getCharge();
				double compByType=charge.getRelativeComp();
				Fmap.put("name", e.getChargeName()+"电费");
				Fmap.put("value",chargeByType);
				pieFValue.add(Fmap);
				totalCharge +=chargeByType;
				totalComp +=compByType;
			}
			Fmap=new HashMap<String,Object>();
			pieLendge_F.add("总电费");
			Fmap.put("name", "总电费");
			Fmap.put("value", Double.parseDouble(df.format(totalCharge)));
			pieFValue.add(Fmap);
			//判断周内的所有状态类型
			List<StateWeek> stateTypes=stateWeekDao.getDistinctType(equId, belongYear, startWeek, endWeek);
			if(types.size()>0){
				for(StateWeek type:stateTypes){
					List<Double> eachDayList=new ArrayList<Double>();
					Map<String, Object> eachDayMap=new HashMap<String, Object>();
					Map<String,Object> eachPieSMap=new HashMap<String,Object>();
					String stateType=type.getStateType();
					pieLendge_S.add(stateType);
					//3状态饼状图
					StateWeek week=stateWeekDao.getdurationByStateAndDate(equId, belongYear, startWeek, endWeek, stateType);
					eachPieSMap.put("name", stateType);
					eachPieSMap.put("value", Double.parseDouble(df.format(week.getDuration()/60/60)));
					pieSValue.add(eachPieSMap);
					//4状态时长(柱状图)
					List<StateWeek> stateWeeks=stateWeekDao.getStateWeekByStateAndDates(equId, stateType, belongYear, startWeek, endWeek);
					int i = 0;
					for(int xt:weeks){
						Double temp = 0d;
						if(i<stateWeeks.size()){
							StateWeek cm = stateWeeks.get(i);
							while(cm.getBelongWeek().equals(xt)){
								temp = Double.parseDouble(df.format(cm.getDuration()/60));
								i++;
								break;
							}
						}
						if(temp!=0d){
							eachDayList.add(temp);
						}else{
							eachDayList.add(0.0);
						}
					}
					eachDayMap.put("name", stateType);
					eachDayMap.put("value", eachDayList);
					yValue_S.add(eachDayMap);
				}
			}
			model.put("success", true);
		}else{
			model.put("success", false);
			model.put("msg", "无数据，请重新选择时间区间");
		}
		model.put("xTimes", weeks);
		model.put("yValue_D",yValue_D );
		model.put("yValue_S", yValue_S);
		model.put("pieLendge_F", pieLendge_F);
		model.put("pieFValue", pieFValue);
		model.put("pieLendge_S", pieLendge_S);
		model.put("pieSValue", pieSValue);
		model.put("totalComp", Double.parseDouble(df.format(totalComp))+"度");
		model.put("overDuration", Double.parseDouble(df.format(overDuration/60/60))+"小时");
		model.put("equName", equName);
		model.put("equNo", equNo);
		model.put("ratedPower", ratedPower+"KW");
		model.put("startTime", belongYear+"年"+startWeek+"周");
		model.put("endTime", belongYear+"年"+endWeek+"周");
//		model.put("maxP_active", maxP_active+"W");
		model.put("path", path);
	}

	@Override
	public void getComprehensiveMonthData(int equId, int year, int startMonth,
			int endMonth, Map<String, Object> model) {
		DecimalFormat  df=new DecimalFormat ("0.0");
		String startTime="";
		String endTime="";
		if(startMonth<10){
			startTime=year+"-"+"0"+startMonth;
		}else{
			startTime=year+"-"+startMonth;
		}
		if(endMonth<10){
			endTime=year+"-"+"0"+endMonth;
		}else{
			endTime=year+"-"+endMonth;
		}
		
		//1.电度趋势和状态时长(折线图和柱状图数据)
		List<String> months=new ArrayList<String>();
		List<Double> yValue_D=new ArrayList<Double>();
		List<Map<String,Object>> yValue_S=new ArrayList<Map<String,Object>>();
		//2.电费和状态时长(饼状图)
		List<String> pieLendge_F=new ArrayList<String>();
		List<Map<String,Object>> pieFValue=new ArrayList<Map<String,Object>>();
		List<String> pieLendge_S=new ArrayList<String>();
		List<Map<String,Object>> pieSValue=new ArrayList<Map<String,Object>>();
		//其他
		Equipment equ=equipmentDao.get(equId);
		String equNo=equ.getEquNo();
		String equName=equ.getEquName();
		String photoPath=equ.getEquPhoto();
		String path="";
		if(photoPath!=null){
			path="/wz_ems/up/"+photoPath;
		}else{
			path="/wz_ems/resources/img/p1.png";
		}
		double ratedPower=equ.getRatedPower();
		double totalCharge=0.0;//全天电费
		double totalComp=0.0;//全天电度
		double overDuration=0.0;//超载总时长
//		Double maxP_active=0.0;//最高功率
		
		//获取月区间里所有的电度类型
		List<ChargeMonth> list=chargeMonthDao.getDistinctChargeName(startTime, endTime);
		if(list.size()>0){
			overDuration=monthDao.getTotalWorkTime(equId, startTime, endTime,"超载");//满载总时长
			//1电度趋势(折线图)
			for(int j=startMonth;j<=endMonth;j++){
				String time="";
				if(j<10){
					time=year+"-"+"0"+j;
				}else{
					time=year+"-"+j;
				}
				ChargeMonth m=chargeMonthDao.getCompByDate(equId, time, "","N");
				yValue_D.add(m.getRelativeComp());
				months.add(time);
			}
			//2电费饼状图
			Map<String,Object> Fmap;
			for(ChargeMonth e:list){
				Fmap=new HashMap<String,Object>();
				pieLendge_F.add(e.getChargeName()+"电费");
				//查询饼状图在相同类型的条件下，时间区间内总共消耗的电度电费值
				ChargeMonth charge=chargeMonthDao.getDurationByChargeNameAndDate(equId, startTime,endTime, e.getChargeName(), "N");
				double chargeByType=charge.getCharge();
				double compByType=charge.getRelativeComp();
				Fmap.put("name", e.getChargeName()+"电费");
				Fmap.put("value",chargeByType);
				pieFValue.add(Fmap);
				totalCharge +=chargeByType;
				totalComp +=compByType;
			}
			Fmap=new HashMap<String,Object>();
			pieLendge_F.add("总电费");
			Fmap.put("name", "总电费");
			Fmap.put("value", Double.parseDouble(df.format(totalCharge)));
			pieFValue.add(Fmap);
			//判断周内的所有状态类型
			List<StateMonth> types=monthDao.getDistinctType(equId, startTime, endTime);
			if(types.size()>0){
				for(StateMonth type:types){
					String stateType=type.getStateType();
					pieLendge_S.add(stateType);
					List<Double> eachDayList=new ArrayList<Double>();
					Map<String, Object> eachDayMap=new HashMap<String, Object>();
					Map<String,Object> eachPieSMap=new HashMap<String,Object>();
					//3状态饼状图
					StateMonth month=monthDao.getDurationByTypeAndDate(equId, startTime, endTime, stateType);
					eachPieSMap.put("name", stateType);
					eachPieSMap.put("value", Double.parseDouble(df.format(month.getDuration()/60/60)));
					pieSValue.add(eachPieSMap);
					//4状态时长(柱状图)
					List<StateMonth> stateMonthList=monthDao.getStateMonthByStateAndDates(equId, startTime, endTime, stateType);
					int i=0;
					for(int k=startMonth;k<=endMonth;k++){
						Double temp = 0d;
						if(i<stateMonthList.size()){
							StateMonth cm = stateMonthList.get(i);
							while(Integer.parseInt(cm.getBelongDate().substring(5))==k){
								temp = Double.parseDouble(df.format(cm.getDuration()/60/60));
								i++;
								break;
							}
						}
						if(temp!=0d){
							eachDayList.add(temp);
						}else{
							eachDayList.add(0.0);
						}
					}
					eachDayMap.put("name", stateType);
					eachDayMap.put("value", eachDayList);
					yValue_S.add(eachDayMap);
				}
			}
			model.put("success", true);
		}else{
			model.put("success", false);
			model.put("msg", "无数据，请重新选择时间区间");
		}
		model.put("xTimes", months);
		model.put("yValue_D",yValue_D );
		model.put("yValue_S", yValue_S);
		model.put("pieLendge_F", pieLendge_F);
		model.put("pieFValue", pieFValue);
		model.put("pieLendge_S", pieLendge_S);
		model.put("pieSValue", pieSValue);
		model.put("totalComp", Double.parseDouble(df.format(totalComp))+"度");
		model.put("overDuration", Double.parseDouble(df.format(overDuration/60/60))+"小时");
		model.put("equName", equName);
		model.put("equNo", equNo);
		model.put("ratedPower", ratedPower+"KW");
		model.put("startTime", year+"年"+startMonth+"月");
		model.put("endTime", year+"年"+endMonth+"月");
//		model.put("maxP_active", maxP_active+"W");
		model.put("path", path);
		
		
	}
	
	
}
